<template>
    <div class="entrust-item">
        <div class="flex justify-between pt-42 pb-20">
            <div class="flex flex-col">
                <div class="flex items-center">
                    <div class="font-31 w-100 " :class="entrust.offset == 'open' ? ' text-green' : 'text-red'">
                        {{ handleWord(entrust.order_price_type, entrust.offset) }}
                    </div>
                    <div class="ml-40 font-31 font-600 textColor">{{ entrust.name || '--' }}</div>
                </div>
            </div>
            <div class="text-grey font-26 flex flex-col justify-between">
                {{ entrust.create_time || '--' }}
            </div>
        </div>
        <div class="flex justify-between pb-34">
            <div class="flex items-center flex-between">
                <div class="w-100">
                    <van-circle v-if="state == 'created'" v-model="finishRate"
                        :rate="(1 - entrust.volume / entrust.volume_open * 100)" :speed="100" :text="finishText"
                        layer-color='#EAEBEF' :color="entrust.offset == 'open' ? '#2EBD85' : '#E35461'" :stroke-width="60"
                        :size="'50px'">
                        <template>
                            <div class="textColor circle-box  flex items-center justify-center">100%</div>
                        </template>
                    </van-circle>
                    <van-circle v-else v-model="currentRate" :rate="(1 - entrust.volume / entrust.volume_open * 100)"
                        :speed="100" :text="text" :color="entrust.offset == 'open' ? '#2EBD85' : '#E35461'"
                        layer-color='#EAEBEF' :stroke-width="60" :size="'60px'">
                        <template>
                            <div class="textColor circle-box  flex items-center justify-center">0%</div>
                        </template>
                    </van-circle>
                </div>
                <div class="ml-20">
                    <div class="flex items-center">
                        <div class="text-grey">
                            <div>{{ $t('数量') }}</div>
                            <!-- <di(USDT)v></div> -->
                        </div>
                        <div class="ml-20 font-26 textColor w-160 break-word">{{ entrust.offset == 'close' ? entrust.volume :
                            (entrust.volume / entrust.price).toFixed(4) || '--' }}
                        </div>
                    </div>
                    <div class="flex mt-20 items-center">
                        <div class="text-grey">{{ $t('价格') }}</div>
                        <div class="ml-20 font-26 textColor">{{ entrust.price || '--' }}</div>
                    </div>
                </div>
            </div>
            <div class="btn-wrap mt-20">
                <button class="detailBtn order-btn text-blue h-60 greyBg mb-20 " @click.stop="goDetail(entrust.order_no)">
                    {{ $t('详情') }}</button>
                <button v-if="state == 'submitted'" class=" order-btn border-none h-60 cancel-btn"
                    @click.stop="cancelSingle(entrust.order_no)">
                    {{ $t('撤单') }}</button>
                <button v-if="state == 'created'" class=" order-btn border-none h-60 cancel-btn text-green">{{
                    $t('已完成') }}</button>
                <button v-if="state == 'canceled'" class=" order-btn border-none h-60 cancel-btn">{{
                    $t('已撤销') }}</button>
            </div>
        </div>
    </div>
</template>

<script>
import { Circle } from 'vant'
export default {
    name: 'EntrustItem', // 订单委托项
    components: {
        [Circle.name]: Circle
    },
    props: {
        entrust: {
            type: Object,
            default() {
                return {}
            }
        },
        state: {
            type: String,
            default: ''
        }
    },
    data() {
        return {
            text: '0',
            currentRate: 0,
            finishRate: 100,
            finishText: '100%',
            item: {}
        }
    },
    watch: {
        entrust(val) {
            console.log(val)
        }
    },
    mounted() {

    },
    methods: {
        handleWord(type, offset) {
            let str1 = type == 'limit' ? this.$t('限价') : this.$t('市价');
            let str2 = offset == 'open' ? this.$t('买入') : this.$t('卖出');
            return str1 + '/' + str2
        },
        goDetail(order_no) { // 详情
            this.$router.push({ name: 'tradeDetail', query: { order_no } })
        },
        cancelSingle(order_no) { // 撤单
            this.$emit('cancelOrder', order_no)
        }
    }
}
</script>
<style lang="scss"  scoped>
.entrust-item {
    @include themify() {
        border-bottom: 1px solid themed("border_color");
    }

    ::v-deep .van-circle__text {
        color: #DAD5DC;
    }

    s .greyBg {
        background: transparent;
    }
}

.btn-wrap {
    display: flex;
    flex-direction: column;
    button {
        padding: 10px 34px;
        border-radius: 6px;
        font-size: 26px;
        min-width: 70px;
        @include themify() {
            background: themed("btn_background2");
        }

        color: #818181;

    }

    .detailBtn {
        @include themify() {
            border: 1px solid themed("btn_background1");
        }


        @include themify() {
            background: themed("btn_background1");
        }

        @include themify() {
            color: themed("color_main");
        }

    }

}

.w-100 {
    min-width: 140px;
}

.circle-box {
    height: 100%;
}

.ml-62 {
    margin-left: 20px;
}
</style>
